import yzSubscribe from "components/ui_components/yz_subscribe";
export default {
  data() {
    return {
      checkList: [],
      Data: [],
      // 可提现数据
      datasource: [],
      show1: false,
      pay_type: '',
      stickStatus: false,
      isCheckAll: false,
      checkAll: false,
      countTotal: '0.00',
      isBalance: false,
      balance_name:''
    }
  },
  created() {
    this.getData();
    // let basic_info = JSON.parse(localStorage.getItem("yz_basic_info"))
    this.balance_name = this.fun.getCustomTextLang('member_center.credit','余额');
  },
  components: { yzSubscribe },
  methods: {
    getData() {
      let url = 'plugin.auction.api.prepayment.withdraw.can-withdraw';
      $http
        .post(
          url, {}, "获取中"
        )
        .then(response => {
          if (response.result == 1) {
            this.Data = response.data;
            this.datasource = response.data.list;
            console.log(this.Data)
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    SelectHandle(val) {
      console.log(val)
      this.show1 = false
    },
    allSelectHandle(e) {
      this.countTotal = this.countTotalPrice();
    },
    // 计算总金额
    countTotalPrice() {
      let total = 0
      this.checkList.forEach(element => {
        total += Number(element.money)
      });
      return total.toFixed(2);
    },
    allSelect(event) {
      this.$refs.checkboxGroup.toggleAll(true);
    },
    stickChange(e) {
      this.stickStatus = e;
    },
    getWithdrawType(e) {
      this.show1 = true;
    },
    getMergeServicetax(e) {
      console.log(this.pay_type, 'ddddddd')
      if (!this.pay_type) {
        this.$dialog.alert({ message: "请选择提现方式" });
        return
      }
      if (this.checkList.length == 0) {
        this.$dialog.alert({ message: "请选择需要提现的保证金" });
        return
      }
      let idsarr = [];
      this.checkList.forEach(element => {
        idsarr.push(element.id)
      });
      let json = {
        withdraw_type: this.pay_type == 'wechat' ? 1 : this.pay_type == 2 ? 2 : 7,
        ids: idsarr
      }
      let url = 'plugin.auction.api.prepayment.withdraw.withdraw';
      $http
        .post(
          url, json, "获取中"
        )
        .then(response => {
          if (response.result == 1) {
            this.$dialog.alert({ message: response.msg });
            this.getData();
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 订阅通知 成功
    confirmSub(e) {
      console.log('成功')
      this.getMergeServicetax();
    },
    // 订阅通知 失败
    errorSub(err) {
      console.log('失败')
      this.getMergeServicetax();
    },
  },

}
